package net.godcode.olivenotes.components.admin;

import java.util.ArrayList;
import java.util.List;

import org.apache.tapestry.annotations.IncludeJavaScriptLibrary;
import org.apache.tapestry.annotations.Persist;
import org.apache.tapestry.ioc.annotations.Inject;
import org.apache.tapestry.upload.services.UploadedFile;
import org.slf4j.Logger;

@IncludeJavaScriptLibrary("ImageSetBuilder.js")
/**
 * ImageSetBuilder
 * 
 * @author Chris Lewis 31/gen/08
 * @version $Id: ImageSetBuilder.java 53 2008-01-31 22:30:42Z burningodzilla $
 */
public class ImageSetBuilder {
	
	//TODO something more flexible
	private static final int MAX_UPLOADS = 4;
	
	@Persist
	private List<UploadedFile> uploadedImages = new ArrayList<UploadedFile>(MAX_UPLOADS);
	
	private int uploadIndex;
	
	private String selectedImages;
	
	@Inject
	private Logger log;
	
	/*
	 * Methods for dealing with file upload components. These are built so that
	 * a variable number of upload components can be rendered and processed
	 * within a loop.
	 */
	
	public UploadedFile getUploadImage() {
		return uploadedImages.get(uploadIndex);
	}
	
	/**
	 * Adds an UploadedFile to the collection.
	 */
	public void setUploadImage(UploadedFile img) {
		if(img != null) {
			uploadedImages.add(img);
		}
	}
	
	/**
	 * @return the uploadIndex
	 */
	public int getUploadIndex() {
		return uploadIndex;
	}

	/**
	 * Updates the index used for accessing the list of uploaded files.
	 * @param uploadIndex the uploadIndex to set
	 */
	public void setUploadIndex(int uploadIndex) {
		this.uploadIndex = uploadIndex;
	}
	
	public List<UploadedFile> getUploadedImages() {
		return uploadedImages;
	}

	public String getSelectedImages() {
		return selectedImages;
	}

	public void setSelectedImages(String selectedImages) {
		this.selectedImages = selectedImages;
	}
	
}
